Mail versenden mit Swiftmailer
Aufruf
Hier die aufrufende Methode:
/**
* send email
*
* @param array $user
* @return void
*/
protected function notify($user) {
// create a Fluid instance for plain text rendering
$renderer = $this->getPlainTextEmailRenderer('mailConfirmRegistration');
// assign the user to it
$renderer->assign('user', $user);
// and do the rendering magic
$message = $renderer->render();
// attachments
$attachmentFile1 = $this->settings["attachmentFile1"];
$attachmentFileName1 = $this->settings["attachmentFileName1"];
$attachmentFile2 = $this->settings["attachmentFile2"];
$attachmentFileName2 = $this->settings["attachmentFileName2"];
$attachments = array($attachmentFileName1=>$attachmentFile1, $attachmentFileName2=>$attachmentFile2);
// finally, send the mail
$this->sendMail($user->getEmail(), $this->settings['mailConfirmRegistrationSubject'], $message, $this->settings['senderEmail'], $this->settings['senderName'],$attachments);
}
Die Einstellungen hierzu in Typoscript:
plugin.tx_rsysworkbook {
settings {
# debugMail
debugMail = 0
# register mail
senderEmail = info@example.com
senderName = Rsys
mailConfirmRegistrationSubject = Ihre Registrierung
# attachments register
attachmentFile1 = fileadmin/user_upload/documents/Information_Studie.pdf
attachmentFileName1 = Information_Studie.pdf
attachmentFile2 = fileadmin/user_upload/documents/img_02.pdf
attachmentFileName2 = Datei02.pdf
}
}
Mail versenden
/**
* send email using swiftmailer
*
* @param string $recipientEmail
* @param string $subject
* @param string $message
* @param string $senderEmail
* @param string $senderName
* @param array $attachments
* @return void
*/
protected function sendMail($recipientEmail, $subject, $message, $senderEmail, $senderName = "", $attachments=array()) {
$mail = t3lib_div::makeInstance('t3lib_mail_message');
$mail->setFrom(array($senderEmail => $senderName));
$mail->setTo(array($recipientEmail => $recipientEmail));
$mail->setSubject($subject);
$mail->setBody($message);
foreach ($attachments as $attachmentFileName=>$attachmentFile) {
$mail->attach(Swift_Attachment::fromPath($attachmentFile,'application/pdf')->setFilename($attachmentFileName));
}
if($this->settings['debugMail'] == 1) {
$this->debug($message);
} else {
$mail->send();
}
}